package com.example.reference_book.util;

import com.example.reference_book.entity.CourseBookInfo;
import com.example.reference_book.filter.CourseBookFilter;
import com.example.reference_book.filter.courseBookImpl.*;

import java.util.List;

public class CourseBookSearchUtil {
    public static CourseBookSearchUtil searchUtil;
    public static List<CourseBookInfo> list;
    private CourseBookSearchUtil (){

    }

    public void init(List<CourseBookInfo> list) {
        this.list = list;
    }

    public static CourseBookSearchUtil getSearchUtil() {
        if (searchUtil == null) {
            synchronized (CourseBookSearchUtil.class) {
                if (searchUtil == null) {
                    searchUtil = new CourseBookSearchUtil();
                }
            }
        }
        return searchUtil;
    }

    public List<CourseBookInfo> searchByKey(int type, String key){
        CourseBookFilter filter;
        switch (type){
            case 1:{
                filter = new CourseBookSchoolFilter();
                break;
            }
            case 2:{
                filter = new CourseBookDeptFilter();
                break;
            }
            case 3:{
                filter = new CourseBookCourseFilter();
                break;
            }
            case 4:{
                filter = new CourseBookBookFilter();
                break;
            }
            default:
                filter = new CourseBookAroundFilter();
        }
        return filter.getList(key,list);
    }
}
